﻿var minimumRecolors = function (blocks, k) {
    let l = 0, r = 0, cnt = 0;
    while (r < k) {
        cnt += blocks[r] === 'W' ? 1 : 0;
        r++;
    }
    let res = cnt;
    while (r < blocks.length) {
        cnt += blocks[r] === 'W' ? 1 : 0;
        cnt -= blocks[l] === 'W' ? 1 : 0;
        res = Math.min(res, cnt);
        l++;
        r++;
    }
    return res;
};
